import re


def print_list(info_list):
    for i in info_list:
        print(i)


with open('data.txt', 'r', encoding='utf8') as f:
    data = f.read()

# <a class="" href="https://sh.lianjia.com/ershoufang/107107235623.html" target="_blank" data-log_index="3" data-el="ershoufang" data-housecode="107107235623" data-is_focus="" data-sl="">16号线+张江南+商场旁+新场古镇Center+精装修</a>
title_list = re.findall('data-is_focus="" data-sl="">(.*?)</a>', data)
# print_list(title_list)

# <div class="totalPrice totalPrice2"><i> </i><span class="">139.8</span><i>万</i></div>
totalPrice_list = re.findall('<span class="">(.*?)</span><i>万', data)
# print_list(totalPrice_list)

# <div class="unitPrice" data-hid="107107214886" data-rid="5011000010208" data-price="15770"><span>15,770元/平</span></div>
unitPrice_list = re.findall('unitPrice" data-hid="(.*?)" data-rid="(.*?)" data-price="(.*?)"><span>(.*?)</span>', data)
# print_list(unitPrice_list)

# <div class="positionInfo"><span class="positionIcon"></span><a href="https://sh.lianjia.com/xiaoqu/5011000010208/" target="_blank" data-log_index="2" data-el="region">江海二村(奉贤) </a>   -  <a href="https://sh.lianjia.com/ershoufang/nanqiao/" target="_blank">南桥</a> </div>
positionInfo_list = re.findall(
    'data-el="region">(.*?) </a>   -  <a href="https://sh.lianjia.com/ershoufang/(.*?)/" target="_blank">(.*?)</a> </div>',
    data)
# print_list(positionInfo_list)

# <div class="houseInfo"><span class="houseIcon"></span>3室1厅 | 88.65平米 | 南 | 简装 | 高楼层(共6层) | 1997年建 | 板楼</div>
houseInfo_list = re.findall('houseInfo"><span class="houseIcon"></span>(.*?)</div>', data)
# print_list(houseInfo_list)

# <div class="followInfo"><span class="starIcon"></span>12人关注 / 11天以前发布</div>
followInfo_list = re.findall('followInfo"><span class="starIcon"></span>(.*?)</div>', data)
# print_list(followInfo_list)

for i in range(len(title_list)):
    print(f"""
        标签：{title_list[i]}
        地址：{positionInfo_list[i][0]} {positionInfo_list[i][2]}
        总价：{totalPrice_list[i]}万
        均价：{unitPrice_list[i][3]}
        描述：{houseInfo_list[i]}
        关注：{followInfo_list[i]}
    """)
